package com.hqm.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hqm.dao.UserDao;
import com.hqm.meta.User;

@Service
public class UserServiceImpl implements UserService{
	@Resource
	private UserDao userDao;
	/**
	 * 验证用户
	 * @param userName 用户名
	 * @param password 密码
	 * @return User 用户对象
	 */
	@Transactional(propagation = Propagation.SUPPORTS)
	public User checkUser(String userName, String password)
		throws Exception{
		if (userName == null || "".equals(userName)) {
			throw new Exception("用户名不能为空");
		}
		if (password == null || "".equals(password)) {
			throw new Exception("密码不能为空");
		}
		
		User user = userDao.getUserByUserName(userName);
		if (user == null) {
			throw new Exception("用户不存在");
		}
		if (!password.equals(user.getPassword())) {
			throw new Exception("密码错误");
		}
		
		return user;
	}

}
